package cn.shanks.dubbo.consume.service.impl;

import cn.hutool.core.lang.Snowflake;
import cn.shanks.common.entity.Order;
import cn.shanks.common.entity.Score;
import cn.shanks.common.service.OrderService;
import cn.shanks.common.service.ScoreService;
import cn.shanks.dubbo.consume.service.PersonService;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Shanks
 * @version 1.0
 * @program cn.shanks.dubbo.consume.service.impl
 * @description
 * @date 2020/9/25 14:14
 */
@Service
public class PersonServiceImpl implements PersonService {

    @DubboReference
    private OrderService orderService;

    @DubboReference
    private ScoreService scoreService;

    @Autowired
    private Snowflake snowflake;

    @Override
    @GlobalTransactional
    public String say(String value) {
        orderService.addOrder(new Order().setId(snowflake.nextId()));
        System.out.println(Integer.valueOf(value) / 1);
        scoreService.addScore(new Score().setId(snowflake.nextId()));
        System.out.println(value);
        return value;
    }
}
